﻿import { NgModule } from '@angular/core';
import { NavigationEnd, Router, RouterModule } from '@angular/router';
import { AuditLogsComponent } from './audit-logs/audit-logs.component';
import { EditionsComponent } from './editions/editions.component';
import { InstallComponent } from './install/install.component';
import { LanguageTextsComponent } from './languages/language-texts.component';
import { LanguagesComponent } from './languages/languages.component';
import { MaintenanceComponent } from './maintenance/maintenance.component';
import { OrganizationUnitsComponent } from './organization-units/organization-units.component';
import { RolesComponent } from './roles/roles.component';
import { HostSettingsComponent } from './settings/host-settings.component';
import { TenantSettingsComponent } from './settings/tenant-settings.component';
import { UiCustomizationComponent } from './ui-customization/ui-customization.component';
import { UsersComponent } from './users/users.component';

@NgModule({
  imports: [
    RouterModule.forChild([
      {
        path: '',
        children: [
          {
            path: 'users',
            component: UsersComponent,
            data: { permission: 'Pages.Administration.Users' }
          },
          {
            path: 'roles',
            component: RolesComponent,
            data: { permission: 'Pages.Administration.Roles' }
          },
          {
            path: 'auditLogs',
            component: AuditLogsComponent,
            data: { permission: 'Pages.Administration.AuditLogs' }
          },
          {
            path: 'maintenance',
            component: MaintenanceComponent,
            data: { permission: 'Pages.Administration.Host.Maintenance' }
          },
          {
            path: 'hostSettings',
            component: HostSettingsComponent,
            data: { permission: 'Pages.Administration.Host.Settings' }
          },
          {
            path: 'editions',
            component: EditionsComponent,
            data: { permission: 'Pages.Editions' }
          },
          {
            path: 'languages',
            component: LanguagesComponent,
            data: { permission: 'Pages.Administration.Languages' }
          },
          {
            path: 'languages/:name/texts',
            component: LanguageTextsComponent,
            data: { permission: 'Pages.Administration.Languages.ChangeTexts' }
          },
          {
            path: 'organization-units',
            component: OrganizationUnitsComponent,
            data: { permission: 'Pages.Administration.OrganizationUnits' }
          },
          {
            path: 'tenantSettings',
            component: TenantSettingsComponent,
            data: { permission: 'Pages.Administration.Tenant.Settings' }
          },
          { path: 'install', component: InstallComponent },
          { path: 'ui-customization', component: UiCustomizationComponent }
        ]
      }
    ])
  ],
  exports: [RouterModule]
})
export class AdminRoutingModule {
  constructor(private router: Router) {
    router.events.subscribe(event => {
      this.hideOpenDataTableDropdownMenus();

      if (event instanceof NavigationEnd) {
        window.scroll(0, 0);
      }
    });
  }

  hideOpenDataTableDropdownMenus(): void {
    let $dropdownMenus = $('.dropdown-menu.tether-element');
    $dropdownMenus.css({
      display: 'none'
    });
  }
}
